package com.ikas.ai.server.module.morningpaper.controller;

import com.ikas.ai.handle.JsonResult;
import com.ikas.ai.server.aop.Pageable;
import com.ikas.ai.server.module.AbstractBean;
import com.ikas.ai.server.module.morningpaper.model.dto.RuntimeDataStatisticsEditDTO;
import com.ikas.ai.server.module.morningpaper.service.RuntimeDataStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 运行数据上报相关接口
 */
@RestController
@RequestMapping("/runtimeData")
public class RuntimeDataStatisticsController extends AbstractBean {

    @Autowired
    private RuntimeDataStatisticsService runtimeDataStatisticsService;

    /**
     * 运行数据上报历史分页列表
     *
     * @param reviewer
     * @param editor
     * @param startDate
     * @param endDate
     * @return
     */
    @Pageable(sortType = "desc", sortBy = "statistics_date")
    @GetMapping("/page")
    public JsonResult queryAlarm(
            @RequestParam(required = false, value = "reviewer") String reviewer,
            @RequestParam(required = false, value = "editor") String editor,
            @RequestParam(required = false,value = "startDate") String startDate,
            @RequestParam(required = false,value = "endDate") String endDate) {
        return JsonResult.ok(runtimeDataStatisticsService.queryPage(reviewer, editor, startDate, endDate));
    }


    /**
     * 运行数据上报编辑
     *
     * @param runtimeDataStatisticsEditDTO
     * @return
     */
    @PostMapping("/edit")
    public JsonResult edit(@RequestBody RuntimeDataStatisticsEditDTO runtimeDataStatisticsEditDTO) {
        runtimeDataStatisticsService.edit(runtimeDataStatisticsEditDTO, getUser());
        return JsonResult.ok();
    }

    /**
     * 运行数据上报审核
     *
     * @param id
     * @return
     */
    @GetMapping("/review/{id}")
    public JsonResult review(@PathVariable("id") Long id) {
        runtimeDataStatisticsService.review(id, getUser());
        return JsonResult.ok();
    }

    /**
     * 运行数据上报详情
     *
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    public JsonResult detail(@PathVariable("id") Long id) {
        return JsonResult.ok(runtimeDataStatisticsService.detail(id));
    }

    /**
     * 获取今日运行数据
     * @return
     */
    @GetMapping("/get")
    public JsonResult get() {
        return JsonResult.ok(runtimeDataStatisticsService.get());
    }

}
